import thread
import sys
thread_count = int(sys.argv[1])
step_count = int(sys.argv[2])
locks = []
threads = []
results = []

def thread_body(start, count, index):
    print "%s\n" % (str(index))
    k = start
    while k < count:
        k+=1
    locks[index].acquire()
    results[index] = k
    locks[index].release()
    return k

for i in range(0, thread_count):
    locks.append(thread.allocate_lock())
    results.append(0)
    threads.append(thread.start_new_thread(thread_body, (0, step_count, i,)))

k = 0
for i in range(0, thread_count):
    ok = 1
    while ok:
        locks[i].acquire_lock()
        if results[i] != 0:
            k += results[i]
            ok = 0
        locks[i].release()
print k